import { SelectProps } from 'naive-ui';
import { reactive } from 'vue';
import { AuthTbRoleApi } from '../AuthTbRole';
import { isLockTextEnum } from './Service';

const getIsLockOptions = () => {
  const temp: any = [];
  Object.keys(isLockTextEnum).forEach(function (key: any) {
    temp.push({
      value: parseInt(key),
      label: isLockTextEnum[key].text,
    });
  });
  return temp.reverse();
};
const getRoleOptions = async () => {
  const { data } = await AuthTbRoleApi.selectList({});
  const result = data.map((it) => {
    return {
      value: it.roleCode,
      label: it.roleName,
    };
  });
  return result;
};
/**这里写一些无需接口定义的options(例如下拉框等) */
const allOptions: Record<string, SelectProps['options']> = {
  isLock: getIsLockOptions()
};
const optionsMap = reactive(new Map());
for (const key in allOptions) {
  optionsMap.set(key, allOptions[key]);
}
/**异步获取选项参数的方法示例 */
async function setstreetName() {
  const res = await getRoleOptions();
  optionsMap.set('authTbRoleList', res);
  optionsMap.set('fkRoleCode', res);
}
let isLoading = false

//TODO 若项目要打成npm包，请务必在局部作用域调用
/**若项目要打成npm包，请务必在局部作用域调用 */
export const getOptionsMap = () => {
  if (!isLoading) {
    setstreetName();
    isLoading = true
  }
  return optionsMap;
};

